<?php
/**
 * CK 开发框架
 * User: Clake
 * Date: 15/6/26
 * Time: 10:37
 */

namespace CK\Util;


use CK\Core\Component;

class Session extends Component{

    private $_conf = [
        //Session 前缀
        'prefix'=>'ck_',
        //Session 存储的类型
        'type'=>'default'
    ];

    private $_prefix;

    public function __construct($conf=null) {
        if (empty($conf)) {
            $conf = C('session');
        }
        if (!empty($conf)) {
            $this->_conf = Arr::mrg($this->_conf,$conf);
        }

        $this->_prefix = $this->_conf['prefix'];

        if (!isset($_SESSION)) {
            session_start();
        }
    }

    public function set($key,$value) {
        $session_name = $this->_prefix.$key;
        $_SESSION[$session_name] = $value;
    }

    public function get($key) {
        $session_name = $this->_prefix.$key;
        return isset($_SESSION[$session_name]) ? $_SESSION[$session_name] : null;
    }

    public function clear() {
        $_SESSION = [];
    }
}